import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base/21_getx/SecondMiddleware.dart';
import 'package:flutter_base/21_getx/allcontrollerbind.dart';
import 'package:flutter_base/21_getx/example.dart';
import 'package:flutter_base/21_getx/get_fristPage.dart';
import 'package:flutter_base/21_getx/get_secondPage.dart';
import 'package:flutter_base/21_getx/get_thirdPage.dart';
import 'package:get/get.dart';
// import 'package:get/get_core/src/get_main.dart';
// import 'package:get/get_navigation/src/root/get_material_app.dart';

/// Getx可以实现路由管理
/// 1.使用GetMaterialApp作为顶层函数
/// 2.调用Get.to(具体界面) 或者Get.toName(路由)
/// 3.Get.back() 返回
/// 4.Get.offAll 返回到根
/// 5.get.off反悔哦跳转
///

void main() {
  runApp(GetMaterialApp(
    home: const MyHomePage21(),

    /// 设置跳转动画，这里设置的是像iOS一样从右到左淡出
    defaultTransition: Transition.rightToLeftWithFade,
    initialBinding: AllControllerBinding(),

    /// 配置路由
    getPages: [
      GetPage(
        name: '/second',
        page: () => const GetSecond21(),
        arguments: {'arguments11': 'arguments223'},
        middlewares: [SecondMiddleWare()],
      ),
      GetPage(name: '/third', page: () => const GetThird()),
    ],
  ));
}

class MyHomePage21 extends StatefulWidget {
  const MyHomePage21({super.key});

  @override
  State<MyHomePage21> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage21> {
  var P = Person21();
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: const Text('Get 路由跳转'),
      ),
      body: Center(
        child: Column(
          children: [
            ElevatedButton(
                onPressed: () {
                  //使用Get跳转到第一个界面
                  Get.to(const GetFrist(), arguments: {'22': 'ssdd'});

                  // P.username.value = '李王ss五';
                  // P.age.value = 3;
                },
                child: const Text('跳转到第一个界面')),
            Divider(),
            Obx(() => Text('${P.username.value}')),
            Obx(() => Text('${P.age.value}')),
          ],
        ),
      ),
    );
  }
}
